package fr.umlv.m2.jee.spij.persistence.education.dao;

import fr.umlv.m2.jee.spij.framework.dao.hibernate.AbstractHibernateDAO;
import fr.umlv.m2.jee.spij.persistence.education.IUnitDAO;
import fr.umlv.m2.jee.spij.persistence.education.Unit;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

/**
 *
 *
 */
@Repository("hibernateUnitDAO")
public class HibernateUnitDAO extends AbstractHibernateDAO<Long, Unit>
        implements IUnitDAO {

    @Override
    public final Unit findByName(final String name) {
        Session session = getHibernateSession();
        Criteria criteria = session.createCriteria(Unit.class);
        criteria.add(Restrictions.like("name", name));
        return (Unit) criteria.uniqueResult();
    }
}
